#!/usr/bin/env python
# -*- coding: utf-8 -*-
# @Time    : 2025/4/15 17:07
# @Author  : Chenmm
# @File    : GenConfig.py
# @Software: PyCharm

from app import db, loginmanager
from datetime import datetime


class GenConfig(db.Model):
    __tablename__ = 'gen_config'

    id = db.Column(db.BigInteger, primary_key=True, autoincrement=True)
    table_name = db.Column(db.String(100), unique=True, nullable=False, comment='表名')
    module_name = db.Column(db.String(100), comment='模块名')
    package_name = db.Column(db.String(255), nullable=False, comment='包名')
    business_name = db.Column(db.String(100), nullable=False, comment='业务名')
    entity_name = db.Column(db.String(100), nullable=False, comment='实体类名')
    author = db.Column(db.String(50), nullable=False, comment='作者')
    parent_menu_id = db.Column(db.BigInteger, comment='上级菜单ID')
    create_time = db.Column(db.DateTime, default=datetime.now, comment='创建时间')
    update_time = db.Column(db.DateTime, onupdate=datetime.now, comment='更新时间')
    is_deleted = db.Column(db.Boolean, default=False, comment='是否删除')

    __table_args__ = {'comment': '代码生成基础配置表'}


class GenFieldConfig(db.Model):
    __tablename__ = 'gen_field_config'

    id = db.Column(db.BigInteger, primary_key=True, autoincrement=True)
    config_id = db.Column(db.BigInteger, db.ForeignKey('gen_config.id'), nullable=False, comment='配置ID')
    column_name = db.Column(db.String(100), comment='列名')
    column_type = db.Column(db.String(50), comment='列类型')
    column_length = db.Column(db.Integer, comment='列长度')
    field_name = db.Column(db.String(100), nullable=False, comment='字段名称')
    field_type = db.Column(db.String(100), comment='字段类型')
    field_sort = db.Column(db.Integer, comment='字段排序')
    field_comment = db.Column(db.String(255), comment='字段描述')
    max_length = db.Column(db.Integer, comment='最大长度')
    is_required = db.Column(db.Boolean, comment='是否必填')
    is_show_in_list = db.Column(db.Boolean, default=False, comment='是否列表显示')
    is_show_in_form = db.Column(db.Boolean, default=False, comment='是否表单显示')
    is_show_in_query = db.Column(db.Boolean, default=False, comment='是否查询显示')
    query_type = db.Column(db.SmallInteger, comment='查询方式')
    form_type = db.Column(db.SmallInteger, comment='表单类型')
    dict_type = db.Column(db.String(50), comment='字典类型')
    create_time = db.Column(db.DateTime, default=datetime.now, comment='创建时间')
    update_time = db.Column(db.DateTime, onupdate=datetime.now, comment='更新时间')

    __table_args__ = {'comment': '代码生成字段配置表'}
